﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Uaf.Core.Tests
{
	[TestClass]
	public class ContainerTest
	{
		private interface ITestClass
		{
		}

		private class TestClass : ITestClass
		{
		}

		[TestMethod]
		public void ResolveInterface()
		{
			var c = new Container();
			var obj = new TestClass();
			c.Register<ITestClass>(obj);
	
			Assert.AreEqual(obj, c.Resolve<ITestClass>());
		}

		[TestMethod]
		public void ResolveByName()
		{
			var c = new Container();
			var obj1 = new TestClass();
			var obj2 = new TestClass();
			c.Register<ITestClass>(obj1, "1");
			c.Register<ITestClass>(obj2, "2");
			c.Register<string>("");

			Assert.AreEqual(obj1, c.Resolve<ITestClass>("1"));
			Assert.AreEqual(obj2, c.Resolve<ITestClass>("2"));
			
			var t = c.ResolveAll<ITestClass>();
			Assert.AreEqual(2, t.Count());
			Assert.AreEqual(obj1, t.First());
			Assert.AreEqual(obj2, t.Last());
		}

		[TestMethod]
		public void ResolveFailed()
		{
			var c = new Container();
			var obj = c.Resolve<TestClass>();
			Assert.IsNull(obj);
		}
	}
}
